home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
Z4Z5EX.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-02
|
5KB
|
153 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: z4z4ex.c
// Title: ZIP+4 Engine
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
//
// This module contains the expander for the ZIP5 file.
// This module should not use any global variables since it must be
// re-entrant.
//
// The code in this module should be written entirely in C.
// Do not use any C++ constructs.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
// SCO UNIX.
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
// SCO UNIX cc
//
//----------------------------------------------------------------------------
#include <z4.h>
//----------------------------------------------------------------------------
// Description: Read a compressed record from the output buffer.
// Parameters: pblk Decoder data structure
// pctyst ZIP5 record
// Returns: TRUE if successful.
// FALSE if no more records found to decode.
//----------------------------------------------------------------------------
BOOL FN_E Z4Z5Expand(PZ4_Z5_BLK pblk, PZ4_Z5 pz5)
{
PBYTE pb;
SIZET cb;
Assert(pblk && pz5);
memset(&pblk->z5, 0, sizeof(pblk->z5));
// Must be at end of buffer
if (pblk->cbNext + MAX_ZIP5_BCD + sizeof(USHORT) >= pblk->cb)
return FALSE;
pb = pblk->pb + pblk->cbNext; // Decode ZIP5
if (pb[0] == 0) // Block not full, but no more records
{
pblk->cbNext = pblk->cb;
return FALSE;
}
strb2a(pb, MAX_ZIP5_BCD, pblk->z5.szZip5, MAX_ZIP5, TRUE);
pb += MAX_ZIP5_BCD;
strb2a(pb, MAX_FINANCE_BCD, pblk->z5.szFinance, MAX_FINANCE, TRUE);
pb += MAX_FINANCE_BCD;
// ZIP5 was zero -- no more records
if (strcmp(pblk->z5.szZip5, "00000") == 0)
return FALSE;
cb = (SIZET)(pb[0] & 0x7F);
if (pb[0] & 0x80)
{
pb++;
cb += (((SIZET)pb[0]) << 7);
pb++;
}
else
pb++;
cb++;
if (!RecIdDecode(pblk->z5.arecid, MAX_ZIP5_CITIES, pb, cb, &pblk->z5.cCities, &pblk->recid))
return FALSE;
Assert(pblk->z5.cCities <= MAX_ZIP5_CITIES);
pb += cb;
cb = (SIZET)(pb - pblk->pb);
Assert(cb <= pblk->cb);
pblk->cbNext = cb;
*pz5 = pblk->z5; // Return a copy of the current record
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Initialize ZIP5 expander
// Parameters: pblk Decoder data structure
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E Z4Z5ExpandInitialize(PZ4_Z5_BLK pblk)
{
Assert(pblk);
memset(pblk, 0, sizeof(Z4_Z5_BLK));
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Reset ZIP5 expander to decode another block of data.
// Parameters: pblk Decoder data structure
// pb Buffer containing compressed data.
// cb Size of buffer.
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E Z4Z5ExpandReset(PZ4_Z5_BLK pblk, PBYTE pb, SIZET cb)
{
Assert(pblk);
pblk->pb = pb; // Set decoding pointers
pblk->cb = cb;
pblk->cbNext = 0;
pblk->recid.usOffset = 0;
pblk->recid.lBlock = 0;
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Terminate ZIP5 expander.
// Parameters: pblk Decoder data structure
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E Z4Z5ExpandTerminate(PZ4_Z5_BLK pblk)
{
Assert(pblk);
memset(pblk, 0, sizeof(Z4_Z5_BLK));
return TRUE;
}
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------